/**
 * 股票收盘价格历史表
 */
var Waterline = require('waterline');
var uuid = require('node-uuid');
var moment = require('moment');

/**
 * @type {void|*}
 */
module.exports = Waterline.Collection.extend({
    identity: 'stock_history_price',
    tableName: 'tb_stock_history_price',
    connection: "mysql",
    attributes: {

        rowId: {
            type: 'string',
            primaryKey: true,
            unique: true,
            required: true,
            uuidv4: true,
            columnName: 'rowid',
            defaultsTo: function () {
                return uuid.v4();
            }
        },
        // createUid: {
        //     type: 'string',
        //     required: true,
        //     columnName: 'createuid',
        //     model: 'user'
        // },
        price:{
            type:'float',
            required: true,
            columnName:'price'
        },
        date:{
            type:'string',
            required: true,
            columnName:'date'
        },
        createdAt:{
            type:'string',
            required: true,
            columnName:'createdAt'
        },
        updatedAt:{
            type:'string',
            required: true,
            columnName:'updatedAt'
        },
        stockId:{
            type: 'string',
            columnName: 'stockId',
            required: true,
            model:"dic_stock"
        },
        toJSON: function () {
            var obj = this.toObject();
            obj.createdAt = moment(obj.createdAt).format('YYYY-MM-DD HH:mm');
            obj.updatedAt = moment(obj.updatedAt).format('YYYY-MM-DD HH:mm');
            obj.date = moment(obj.date).format('YYYY-MM-DD');
            return obj;
        }

    }
});
